package com.android.studyspot;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;


/**
 * This class binds the visual StudySpot Views and the data behind them (StudySpots).
 */
public class StudySpotListAdapter extends BaseAdapter {

	/** The application Context in which this StudySpotListAdapter is being used. */
	private Context m_context;

	/** The data set to which this StudySpotListAdapter is bound. */
	private List<StudySpot> m_studySpotList;
	
	private Typeface tf;

	public StudySpotListAdapter(Context context, List<StudySpot> studySpotList, Typeface typeFace) {
		this.m_context = context;
		this.m_studySpotList = studySpotList;
		this.tf = typeFace;
	}

	@Override
	public int getCount() {
		return this.m_studySpotList.size();
	}

	@Override
	public Object getItem(int position) {
		return this.m_studySpotList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		
		if (convertView == null) {
			Log.d("study-spot", this.m_studySpotList.get(position).getCourse());
			
			StudySpotView sSV = new StudySpotView(m_context, this.m_studySpotList.get(position));
			
			TextView courseTV = (TextView) sSV.findViewById(R.id.ss_course);
			TextView dateTV = (TextView)sSV.findViewById(R.id.ss_date);
			TextView timeTV = (TextView)sSV.findViewById(R.id.ss_time); 

	        if(this.m_studySpotList.get(position) != null )
	        {
	        	courseTV.setTypeface(tf);
	        	dateTV.setTypeface(tf);
	        	timeTV.setTypeface(tf);
	        }
			
			return sSV;
		}
		else {
			convertView = new StudySpotView(m_context, this.m_studySpotList.get(position));
			
			TextView text = (TextView) convertView.findViewById(R.id.ss_course);
			TextView dateTV = (TextView)convertView.findViewById(R.id.ss_date);
			TextView timeTV = (TextView)convertView.findViewById(R.id.ss_time); 

	        if(this.m_studySpotList.get(position) != null )
	        {
	        	text.setTypeface(tf);
	        	dateTV.setTypeface(tf);
	        	timeTV.setTypeface(tf);
	        }
			
			return convertView;
		}
	}
}
